﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DevExpress.Web.ASPxGridView;
using RR;

/// <summary>
/// Сводное описание для AppUtils
/// </summary>
public static class AppUtils
{
    private static RegistRar regrar = new RegistRar();

    public static void FocusInsertedRow(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e)
    {
        ASPxGridView grid = (ASPxGridView) sender;
        grid.FocusedRowIndex = grid.FindVisibleIndexByKeyValue(e.NewValues["CODE"]);
    }

    public static void FocusUpdatedRow(object sender, DevExpress.Web.Data.ASPxDataUpdatedEventArgs e)
    {
        ASPxGridView grid = (ASPxGridView)sender;
        grid.FocusedRowIndex = grid.FindVisibleIndexByKeyValue(e.NewValues["CODE"]);
    }

    public static int GetPageCount()
    {
        var query = (from g in regrar.GLOBALDATA
            where g.CODE == 1
            select g).FirstOrDefault();
        if (query != null)
        {
            return Convert.ToInt32(query.DATA);
        }
        else
        {
            return 30;
        }
    }
}